<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/1/15
 * Time: 23:05
 */
namespace app\admin\logic\transfer_driver;
use app\admin\model\User;
use app\common\library\BankMatch;
use app\common\model\zbtask\Money;
use think\Db;
use think\exception\ValidateException;


/**
 * 打款上层服务
 */
class Base
{
    public function getUser($id) {
        $user = User::get($id);
        if (!$id) {
            throw new ValidateException('获取用户信息失败');
        }

        return $user;
    }

    public function getMoney($id) {
        $money = Money::get($id);
        if (!$money) {
            throw new ValidateException('未获取到该条众包费');
        }

        return $money;
    }

    public function log($money, $type, $msg,$plat) {
        $log['task_money_id'] = $money['id'];
        $log['createtime'] = time();
        $log['account'] = $money['bank_card'];
        $log['type'] = $type;
        $log['pay_type'] = $money['pay_type'];
        $log['msg'] = $msg;
        $log['pay_plat'] = $plat;

        Db::name('zbtask_moneylog')->insert($log);
    }



    //回调方法
    public function lineNotify($money_id, $success = true) {
        if ($success) {
            $data['transfer_type'] = 2;
            $data['pay_time'] = time();
        } else {
            $data['transfer_type'] = 3;
            $data['pay_time'] = time();
        }

        Money::where('id', $money_id)->update($data);
    }
}